/*********************\
* Author:Dzlua
* QQ:505544956
* Time:2017/04/16
\**********************/
#include "LuaTreeView.h"

#define CObjPtr ((CTreeViewUI*)m_cobj)

namespace DuiLib {

UINT LuaTreeView::GetListType()
{
    return CObjPtr->GetListType();
}

int LuaTreeView::Add(LuaState *L)
{
    LuaStack args(L);
    bool bRet = false;
    CTreeNodeUI* ctrl = (CTreeNodeUI*)LuaHelperNS::GetCObjectData(args[2]);
    bRet = CObjPtr->Add(ctrl);
    L->PushBoolean(bRet);
    return 1;
}

int LuaTreeView::AddAt(LuaState *L)
{
    LuaStack args(L);
    CTreeNodeUI* ctrl = (CTreeNodeUI*)LuaHelperNS::GetCObjectData(args[2]);
    if (args[3].IsInteger()) {
        int index = LuaHelperNS::GetInt(args[3], -1);
        long iRet = CObjPtr->AddAt(ctrl, index);
        L->PushInteger(iRet);
    } else {
        CTreeNodeUI* index = (CTreeNodeUI*)LuaHelperNS::GetCObjectData(args[3]);
        bool bRet = CObjPtr->AddAt(ctrl, index);
        L->PushBoolean(bRet);
    }
    return 1;
}

int LuaTreeView::Remove(LuaState *L)
{
    LuaStack args(L);
    bool bRet = false;
    CTreeNodeUI* ctrl = (CTreeNodeUI*)LuaHelperNS::GetCObjectData(args[2]);
    bRet = CObjPtr->Remove(ctrl);
    L->PushBoolean(bRet);
    return 1;
}

bool LuaTreeView::RemoveAt(int iIndex)
{
    return CObjPtr->RemoveAt(iIndex);
}

void LuaTreeView::RemoveAll()
{
    CObjPtr->RemoveAll();
}

int LuaTreeView::SetItemCheckBox(LuaState *L)
{
    LuaStack args(L);
    bool _Selected = LuaHelperNS::GetBool(args[2]);
    CTreeNodeUI* ctrl = (CTreeNodeUI*)LuaHelperNS::GetCObjectData(args[3]);
    bool bRet = CObjPtr->SetItemCheckBox(_Selected, ctrl);
    L->PushBoolean(bRet);
    return 1;
}

int LuaTreeView::SetItemExpand(LuaState *L)
{
    LuaStack args(L);
    bool _Selected = LuaHelperNS::GetBool(args[2]);
    CTreeNodeUI* ctrl = (CTreeNodeUI*)LuaHelperNS::GetCObjectData(args[3]);
    CObjPtr->SetItemExpand(_Selected, ctrl);
    return 0;
}

void LuaTreeView::SetVisibleFolderBtn(bool _IsVisibled)
{
    CObjPtr->SetVisibleFolderBtn(_IsVisibled);
}

bool LuaTreeView::GetVisibleFolderBtn()
{
    return CObjPtr->GetVisibleFolderBtn();
}

void LuaTreeView::SetVisibleCheckBtn(bool _IsVisibled)
{
    CObjPtr->SetVisibleCheckBtn(_IsVisibled);
}

bool LuaTreeView::GetVisibleCheckBtn()
{
    return CObjPtr->GetVisibleCheckBtn();
}

void LuaTreeView::SetItemMinWidth(UINT _ItemMinWidth)
{
    CObjPtr->SetItemMinWidth(_ItemMinWidth);
}

UINT LuaTreeView::GetItemMinWidth()
{
    return CObjPtr->GetItemMinWidth();
}

void LuaTreeView::SetItemTextColor(DWORD _dwItemTextColor)
{
    CObjPtr->SetItemTextColor(_dwItemTextColor);
}

void LuaTreeView::SetItemHotTextColor(DWORD _dwItemHotTextColor)
{
    CObjPtr->SetItemHotTextColor(_dwItemHotTextColor);
}

void LuaTreeView::SetSelItemTextColor(DWORD _dwSelItemTextColor)
{
    CObjPtr->SetSelItemTextColor(_dwSelItemTextColor);
}

void LuaTreeView::SetSelItemHotTextColor(DWORD _dwSelHotItemTextColor)
{
    CObjPtr->SetSelItemHotTextColor(_dwSelHotItemTextColor);
}

SDLUA_BEGIN_REGISTER(LuaTreeView, TreeView, List)
    SDLUA_REGISTER_FUN_CPP(LuaTreeView, GetListType, GetListType)

    SDLUA_REGISTER_FUN_LUA(LuaTreeView, Add, Add)
    SDLUA_REGISTER_FUN_LUA(LuaTreeView, AddAt, AddAt)
    SDLUA_REGISTER_FUN_LUA(LuaTreeView, Remove, Remove)
    SDLUA_REGISTER_FUN_CPP(LuaTreeView, RemoveAt, RemoveAt)
    SDLUA_REGISTER_FUN_CPP(LuaTreeView, RemoveAll, RemoveAll)

    SDLUA_REGISTER_FUN_LUA(LuaTreeView, SetItemCheckBox, SetItemCheckBox)
    SDLUA_REGISTER_FUN_LUA(LuaTreeView, SetItemExpand, SetItemExpand)

    SDLUA_REGISTER_FUN_CPP(LuaTreeView, SetVisibleFolderBtn, SetVisibleFolderBtn)
    SDLUA_REGISTER_FUN_CPP(LuaTreeView, GetVisibleFolderBtn, GetVisibleFolderBtn)
    SDLUA_REGISTER_FUN_CPP(LuaTreeView, SetVisibleCheckBtn, SetVisibleCheckBtn)
    SDLUA_REGISTER_FUN_CPP(LuaTreeView, GetVisibleCheckBtn, GetVisibleCheckBtn)
    SDLUA_REGISTER_FUN_CPP(LuaTreeView, SetItemMinWidth, SetItemMinWidth)
    SDLUA_REGISTER_FUN_CPP(LuaTreeView, GetItemMinWidth, GetItemMinWidth)
    SDLUA_REGISTER_FUN_CPP(LuaTreeView, SetItemTextColor, SetItemTextColor)
    SDLUA_REGISTER_FUN_CPP(LuaTreeView, SetItemHotTextColor, SetItemHotTextColor)
    SDLUA_REGISTER_FUN_CPP(LuaTreeView, SetSelItemTextColor, SetSelItemTextColor)
    SDLUA_REGISTER_FUN_CPP(LuaTreeView, SetSelItemHotTextColor, SetSelItemHotTextColor)

SDLUA_END_REGISTER

SDLUA_BEGIN_UNREGISTER(LuaTreeView, TreeView)
SDLUA_END_UNREGISTER(TreeView)

}

#undef CObjPtr